package com.kd.juhaowan.view;

import android.content.Context;
import android.content.res.ColorStateList;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.kd.juhaowan.R;

import butterknife.BindView;
import butterknife.ButterKnife;

public class CustomTabView extends FrameLayout {

    @BindView(R.id.mall_view_tab_title)
    TextView title;

    @BindView(R.id.mall_view_tab_icon)
    ImageView indicator;

    public CustomTabView(@NonNull Context context) {
        super(context);
        loadSubContentView();
    }

    public CustomTabView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        loadSubContentView();
    }

    public CustomTabView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        loadSubContentView();
    }

    public CustomTabView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        loadSubContentView();
    }

    private void loadSubContentView() {
        ButterKnife.bind(this, LayoutInflater.from(getContext()).inflate(R.layout.mall_view_tab, this, true));
    }

    @Override
    public void setSelected(boolean selected) {
        super.setSelected(selected);
        this.title.setSelected(selected);
        this.indicator.setSelected(selected);
    }

    public void setTextColor(ColorStateList colors){
        this.title.setTextColor(colors);
    }

    public void setText(CharSequence text){
        this.title.setText(text);
    }

    public void setIcon(int resId){
        this.indicator.setImageResource(resId);
    }
}
